//
//  CenterMenuView.m
//  EasyToTesco2.0
//
//  Created by 杨森 on 16/5/31.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "CenterMenuView.h"

@interface CenterMenuView()
{
    UIView *bgView;
}

@property(nonatomic,strong)NSArray *menuArray;

@end

@implementation CenterMenuView

- (instancetype)initWithFrame:(CGRect)frame MenuArr:(NSArray *)menuArr
{
    if (self = [super initWithFrame:frame]) {
        _menuArray = menuArr;
        
        [self addMenuView];
    }
    return self;
}

- (void)addMenuView
{
    
    for (NSInteger i = 0; i < 8; ++i) {
        
        CGFloat HIGH = self.Height/2.2;
        
        int maxCol = 4;
        CGFloat col = i % maxCol;
        CGFloat row = i / maxCol;
        
        CGRect frame = CGRectMake(col*WIDTH/4.3,15+row*HIGH,WIDTH/4, HIGH);
        
        UIView *menubackView = [[UIView alloc] initWithFrame:frame];
        menubackView.tag = 10+i;
        [self addSubview:menubackView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnTapBtnView:)];
 
        [menubackView addGestureRecognizer:tap];
        
        CGFloat frameWidth = frame.size.width/2.2;
        //图
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(frameWidth/1.25,0, frameWidth, frameWidth)];
        imageView.layer.cornerRadius = frameWidth/2;
        imageView.layer.masksToBounds = YES;
//        imageView.backgroundColor = DEFAULT_COLOR;
        imageView.contentMode = UIViewContentModeCenter;
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"shouye_old_%ld",i]];
        [menubackView addSubview:imageView];
        
        //文字
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(imageView.x-5, CGRectGetMaxY(imageView.frame)+5,frameWidth+15, 20)];
        titleLabel.font = [UIFont systemFontOfSize:12];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.text = [NSString stringWithFormat:@"%@",_menuArray[i]];
        titleLabel.textColor = [UIColor grayColor];
        [menubackView addSubview:titleLabel];
        
        
    }
    
    
}

-(void)OnTapBtnView:(UITapGestureRecognizer *)sender{
//    NSLog(@"tag:%ld",sender.view.tag);
    if ([self.delegate respondsToSelector:@selector(homeMenuDidSelectedAtIndex:)]) {
        [self.delegate homeMenuDidSelectedAtIndex:sender.view.tag];
    }
}
@end
